﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agr.Questionnaire.Core.Domain.Qnnaire.Events;
using Agr.CQRS.ViewModel;
using Agr.CQRS.Infrastructure.ServiceBus;
using Agr.CQRS.Infrastructure.Orm;

namespace Agr.Questionnaire.Core.ViewModel.Qnnaire
{
    public class QuestionnaireDetailUpdater : ViewModelUpdater<QuestionnaireDetail>
    {
        public QuestionnaireDetailUpdater(OrmContext ctx) : base(ctx) { }

        private void handle(QuestionnaireNamedEvent ev)
        {
            CurrentRecord.Name = ev.Name;
        }

        private void handle(TextQuestionAddedEvent ev)
        {
            var aq = new QuestionnaireDetail_AnswerableQuestionInList();
            aq.EntityNumber = ev.Entitynumber;
            aq.SequenceNumber = ev.SequenceNumber;

            aq.QuestionType = "Text question";
            aq.Question = ev.QuestionText;

            CurrentRecord.AddAnswerableQuestion(aq);
        }
    }
}
